//
//  HoroscopeSelector.m
//  Astro
//
//  Created by ACER on 12/1/11.
//  Copyright (c) 2011 __MyCompanyName__. All rights reserved.
//

#import "HoroscopeSelector.h"
#import "CTDatabase.h"
#import "VCResult.h"
#import "CTServer.h"
#import "LuckyNumberViewController.h"
#import "DailyViewController.h"
#import "LuckyNumberContent.h"

@implementation HoroscopeSelector

@synthesize result,	db;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
    withHoroscopeSelected:(int)selected
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
		horoscopeSelected = selected;
		
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
	
//	NSLog(@"horoscopeSelected = %d",horoscopeSelected);
	
}

- (void) viewWillAppear:(BOOL)animated{
	AstroAppDelegate *appDelegate = APP_DELEGATE;
	[appDelegate bottomButtonControlWithState:BBStateShowAbout andType:BBTypeWest];
	appDelegate = nil;
	
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

//======================================

-(IBAction) astrologyChartSelected:(id)sender {
	UIButton *btn = (UIButton*)sender;
	AstroAppDelegate *appDL = APP_DELEGATE;
	NSInteger userId = [[appDL userInfo] userid]; 
	if (horoscopeSelected == 5) {
		LuckyNumberContent *luckyNumberContent = [CTServer requestURLGetLuckyNumberInfo:userId withCungUser:btn.tag]; 
	//	NSLog(@"luckyNumber : %d", luckyNumberContent.luckyNum);
	//	NSLog(@"content: %@", luckyNumberContent.content);
		LuckyNumberViewController *viewInfo = [[LuckyNumberViewController alloc] initWithNibName:@"LuckyNumberViewController" bundle:nil
																					withLuckyNumber:luckyNumberContent.luckyNum];
		[self.navigationController pushViewController:viewInfo animated:YES];
		viewInfo.sc_textResult.text = luckyNumberContent.content;
		
	}else if (horoscopeSelected == 6) {
		NSString *dailyInfo = [CTServer requestURLGetDailyInfo:userId withCungUser:btn.tag];
	//	NSLog(@"dailyInfo : %@", dailyInfo);
		DailyViewController *viewDailyInfo = [[DailyViewController alloc] initWithNibName:@"DailyViewController" bundle:nil
																					withCungUser:btn.tag];
		[self.navigationController pushViewController:viewDailyInfo animated:YES];
		viewDailyInfo.sc_textResult.text = dailyInfo;
		
	}else {
		NSString *content, *iconName;
		db = [[CTDatabase alloc] init];
		
		content = [db getToken:horoscopeSelected andSignId:btn.tag];
		iconName = [db getIconSigns:btn.tag];
		
		result = [[VCResult alloc] initWithNibName:@"VCResult" bundle:nil];	
		[self.navigationController pushViewController:result animated:YES];
		
		result.textResult.text = content;
		//	[result.imgContent setImage:[UIImage imageNamed:iconName]];
		[result.imgBg setImage:[UIImage imageNamed:@"Common.BackgroundPhuongTay.png"]];
	}

	
	
}

@end
